#!/bin/bash

echo -e "---------------------------------------------------------"

echo -e "`date` --- begin common logs"

function deletes(){
    local path="$1"
    find ${path} -type f -ctime +2 \( -name "*.log*" -o -name "*.hprof*" -o -name "*.dump*" \)
    find ${path} -type f -ctime +2 \( -name "*.log*" -o -name "*.hprof*" -o -name "*.dump*" \) | xargs rm -rf
    find ${path} -type f -mtime +2 \( -name "*.log*" -o -name "*.hprof*" -o -name "*.dump*" \)
    find ${path} -type f -mtime +2 \( -name "*.log*" -o -name "*.hprof*" -o -name "*.dump*" \) | xargs rm -rf
}

echo -e "`date` --- clean /opt/app/"
mkdir -p /opt/app/
cd /opt/app/
deletes "/opt/app/"

echo -e "`date` --- clean /opt/log/"
mkdir -p /opt/log/
cd /opt/log/
deletes "/opt/log/"

echo -e "`date` --- clean /opt/jvm/"
mkdir -p /opt/jvm/
cd /opt/jvm/
deletes "/opt/jvm/"

echo -e "`date` --- clean /var/lib/rancher/fluentd/log/buffer/cluster.buffer/"
mkdir -p /var/lib/rancher/fluentd/log/buffer/cluster.buffer/
cd /var/lib/rancher/fluentd/log/buffer/cluster.buffer/
deletes "/var/lib/rancher/fluentd/log/buffer/cluster.buffer/"

echo -e "`date` --- finish common logs"

echo -e "---------------------------------------------------------"

# 00 01 * * * sh /opt/job/cleanup-scripts/clean-common-logs.sh  >> /opt/job/cleanup-scripts/logs/clean-common-logs.log
